<?php 

//用户的控制器
class UserController extends Controller
{
    //存放模型对象
    private $model = null;
    public function __construct()
    {
        //调用执行  父级的构造方法
        parent:__construct();
        $this->model = new Model('user');
    }
    public function index()
    {
        $data = $this->model->order('id desc')->select();
        $this->assign('title','用户列表');
        $this->assign('list',$data);
        $this->display('User/index.html')
    }

    //加载表单
    public function add()
    {
        $this->assign('title','填个用户啊');
        $this->display('User/add.html');
    }
    //执行tianjia操作
    public function  insert()
    {
        if($this->model->add()>0){
           $this->redirect('恭喜你,插入成功','/index.php?m=User');
        }else{
            $this->redirect('恭喜你，插入失败');
        }
    }
    //执行删除
    public function del()
    {
        if($this->model->del($_GET['id'])){
            $this->redirect('恭喜您,删除成功!','./index.php?m=User');
        }else{
            $this->redirect('恭喜您,删除失败!','./index.php?m=User');
        }
    }
    //加载编辑页面
    public function edit()
    {
        $data = $this->$model->find($_GET['id']);
        $this->assign('title','编辑用户');
        $this->assign('data',$data);
        $this->display('User/edit.html');
    }
    public function update()
    {
        if($this->model->update()>0){
           $this->redirect('恭喜您,修改成功!','./index.php?m=User')
        }else{
           $this->redirect('恭喜您,修改失败鸟!!!!');
        }

    }
}


